package sk.tramtatiri.pages.users;

import java.text.DecimalFormat;

import org.apache.wicket.Page;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;

import sk.tramtatiri.core.IConstants;

public class ManualBMIPage extends UserPageTemplate {

	private TextField<String> heightBMI;
	private TextField<String> weightBMI;
	private FeedbackPanel feedback;
	private Panel panel0;

	public ManualBMIPage() {
		feedback = new FeedbackPanel("feedback");
		feedback.setOutputMarkupId(true);
		
		panel0 = new BMIResultPanel("panel0");
		panel0.setVisible(false);
		
		BMIInformationPanel panel1 = new BMIInformationPanel("panel1");
		panel1.setVisible(true);
		
		heightBMI = new TextField<String>("heightBMI",Model.of(""));
		heightBMI.setType(int.class);
		heightBMI.setRequired(true);
		heightBMI.setLabel(new Model<String>("heightBMI"));
		
		weightBMI = new TextField<String>("weightBMI",Model.of(""));
		weightBMI.setType(int.class);
		weightBMI.setRequired(true);
		weightBMI.setLabel(new Model<String>("weightBMI"));
		
		Form< ? > form = new Form<Void>("BMIcalcForm") {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = -476217841067553778L;

			@Override
			protected void onSubmit() {
				int weightValue = Integer.parseInt(weightBMI.getInput());
				int heightValue = Integer.parseInt(heightBMI.getInput());
				double heightValueInM = heightValue / 100.0;
				double bmi = weightValue / Math.pow(heightValueInM, 2);
				
				((BMIResultPanel) panel0).setNewBMIResult(bmi);
				panel0.setVisible(true);
			}
		};
		
		add(form);
		
		form.add(heightBMI);
		form.add(weightBMI);
		
		add(feedback);
		add(panel0);
		add(panel1);
	}

	@Override
	public String getPageTitle() {
		return IConstants.PAGE_NAME+" - BMI kalkulacka";
	}
}
